package com.is.control;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.is.dbconn.DBConnect;
import com.is.model.ParamReasonType;

public class ParamReasonTypeControl {
	public static List<ParamReasonType> getAllReaons(){
		DBConnect dbConnect = new DBConnect();
		List<ParamReasonType> reasons = new ArrayList<ParamReasonType>();
		String sql = "select * from param_reasontype order by id";
		dbConnect.prepareStatement(sql);
		ResultSet rs = null;
		try {
			rs = dbConnect.executeQuery();
			while(rs.next()){
				ParamReasonType prt = new ParamReasonType();
				prt.setId(rs.getInt("id"));
				prt.setReasonType(rs.getString("reasonType"));
				reasons.add(prt);
			}
			return reasons;
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("getAllReasons Error");
		}finally{
			dbConnect.close();
		}
		return null;
	}
	
	public static String getTypeNameById(int id){
		DBConnect dbConnect = new DBConnect();
		String type ="";
		String sql = "select reasonType from param_reasontype where id="+id;
		dbConnect.prepareStatement(sql);
		ResultSet rs = null;
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
			    type=rs.getString("reasonType");
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("getAllReasons Error");
		}finally{
			dbConnect.close();
		}
		return type;
	}
	public static HashMap getRessonMap(){
		String sql = "select * from param_reasontype";
		DBConnect dbc = new DBConnect();
		dbc.prepareStatement(sql);
		ResultSet rs = null;
		HashMap map = new HashMap();
		try{
			rs = dbc.executeQuery();
			while(rs.next()){
				map.put(rs.getInt("id"), rs.getString("reasonType"));
			}
			return map;
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("getRessonMap ERROR");
		} finally{
			dbc.close();
		} 
		return null;
	}
}
